import axios from 'axios'

axios.interceptors.request.use(config => {
    if (localStorage.getItem('MyToken')) {
        config.headers['Authorization'] = localStorage.getItem('MyToken')
    }
    return config
}, err => {
    return Promise.reject(err)
})

axios.interceptors.response.use(config => {
    return config
}, err => {
    if (err.response.status == 401) {
        localStorage.removeItem('MyToken')
    }
    return Promise.reject(err)
})

export default axios